<?php
require 'spl.php';

function required_valid($p_1, $p_2, $p_3, $p_4, $p_5) {
    //初始化

    $Parameters = new \liyuze\Parameters\Parameters();
    //配置参数和验证规则
    $Parameters->config([
        'p_1' => [$p_1, 'number' ],
        'p_2' => [$p_2, 'integer' ],
        //等效于
        //'p_2' => [$p_2, ['number', 'mustInt' => true]],
        'p_3' => [$p_3, ['number', 'max' => 9.9] ],
        'p_4' => [$p_4, ['integer', 'min' => 0]],
        'p_5' => [$p_5, ['integer', 'equal' => 1]],
    ], true);

    //验证
    $Parameters->validate();

    return $Parameters->getErrors();
}

function test_pass()
{
    $p_1 = 1.2;
    $p_2 = 1;
    $p_3 = 5.5;
    $p_4 = 1;
    $p_5 = 1;
    $r = required_valid($p_1, $p_2, $p_3, $p_4, $p_5);
    return json_encode($r, 256);
}


function test_error()
{
    $p_1 = '1';
    $p_2 = 1.2;
    $p_3 = 10;
    $p_4 = -1;
    $p_5 = 0;
    $r = required_valid($p_1, $p_2, $p_3, $p_4, $p_5);
    return json_encode($r, 256);
}

var_dump(
    test_pass(),
    test_error()
);

